precision mediump float;

uniform vec4 ambientColor;
uniform vec4 diffuseColor;

uniform sampler2D colorMap;
uniform sampler2D normalMap;

varying vec3 vVaryingLightDir;
varying vec2 vTexCoords;

void main(){
	vec3 vTextureNormal=texture2D(normalMap,vTexCoords).xyz;
	vTextureNormal=(vTextureNormal-0.5)*2.0;
	
	float diff=max(0.0, dot( normalize(vTextureNormal),normalize(vVaryingLightDir) ));
	vec4 vFragColor = diff*diffuseColor;
	vFragColor += ambientColor;
	
	vFragColor.rgb=min(vec3(1.0,1.0,1.0),vFragColor.rgb);
	
	vFragColor*=texture2D(colorMap,vTexCoords);
	
	gl_FragColor=vFragColor;
}